package com.itheima.controller;

import com.itheima.entity.Comment;
import com.itheima.entity.Movies;
import com.itheima.result.Result;
import com.itheima.service.CommentService;
import com.itheima.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/single")
public class SingleController {
    @Autowired
    private MovieService movieService;

    @Autowired
    private CommentService commentService;

    /**
     * 获取影视详情
     *
     * @return
     */
    @GetMapping("/findMovieById")
    public Result findMovieById(@RequestParam Integer id) {
        Movies movies = movieService.findById(id);
        return Result.success(movies);
    }


    /**
     * 获取影视评论信息
     *
     * @return
     */
    @GetMapping("/findMovieCommentListByMovieId")
    public Result findMovieCommentListByMovieId(@RequestParam Integer id) {
        List<Comment> comment = commentService.findByMovieId(id);
        return Result.success(comment);
    }


    /**
     * 保存评论信息
     *
     * @return
     */
    @PostMapping("/saveComment")
    public Result saveComment(@RequestBody Comment comment) {
        commentService.save(comment);
        return Result.success();
    }


}
